<template>
  <div>
    <!-- 分页插件进行封装 -->
    <n-pagination
      v-model:page="currentPage"
      v-model:page-size="pageSize"
      :size="size"
      :page-sizes="[10, 20, 30, 40]"
      :show-quick-jumper="showJumper"
      :show-size-picker="showPicker"
      @update:page="handleCurrentChange"
      @update:page-size="handleSizeChange"
      :page-slot="pageSlot"
      :item-count="total"
    />
  </div>
  <!-- <div>{{ boxSize }}</div> -->
</template>

<script setup lang="ts">
import { ref, computed } from "vue";
const props = defineProps({
  size: {
    type: String,
    default() {
      return "medium";
    },
  },
  total: {
    type: Number,
    required: true,
  },
  page: {
    // 当前页码
    type: Number,
    default: 1,
  },
  limit: {
    type: Number,
    default: 10,
  },
});
const emit = defineEmits(['update:page','update:limt','pagination']);
const currentPage = computed({
  set(val) {
    emit("update:page", val);
  },
  get() {
    return props.page;
  },
});
const pageSize = computed({
  set(val) {
    emit("update:limt", val);
  },
  get() {
    return props.limit;
  },
});
let handleCurrentChange = (page: number) => {
  emit("pagination", {
    page: page,
    limit: pageSize.value,
  });
};
let handleSizeChange = (page: number) => {
  emit("pagination", {
    currentPage: currentPage.value,
    limit: page,
  });
};
const vieWidth = ref();
vieWidth.value = document.documentElement.clientWidth || document.body.clientWidth;
let showPicker = computed(() => {
  return vieWidth.value < 992 ? false : true;
});
let showJumper = computed(() => {
  return vieWidth.value < 992 ? false : true;
});
let pageSlot = computed(() => {
  return vieWidth.value < 992 ? 5 : 9;
}); // 监听
window.onresize = () => {
  vieWidth.value = document.documentElement.clientWidth || document.body.clientWidth;
};
</script>
<style scoped></style>
